<?php

/**
 * Flickr Photosets - Configuration Page
 * Allows the user to set their configuration.
 * 
 * @author Brad Dougherty <bdougherty@gmail.com>
 * @license http://www.gnu.org/licenses/gpl.html GNU General Public License 3.0
 */

/*
Require the function library
This will include all other necessary files
*/
require_once 'lib.php';

/*
Initialize Flickr Photosets
*/
$fp = new FP_Config();

?>

<?=$fp->get_script('common')?>
<script type="text/javascript">
var profile_display_sets = '<?=$fp->profile_display['sets']?>';
var profile_display_random_sets = '<?=$fp->profile_display['random_sets']?>';
var profile_display_overview = '<?=$fp->profile_display['overview']?>';
</script>
<?=$fp->get_script('configure')?>

<fb:title>Configuration</fb:title>
<?=$fp->get_stylesheet('configure')?>
<?=$fp->get_header('configure', '<fb:application-name linked="false" /> Configuration', true)?>

<?php
/*
Show the option to Authenticate if no information is present in the database
*/
if (!$fp->is_flickr_authorized()) { ?>
	
	<?=$fp->print_messages()?>
	
	<div class="boxes clearfix">
		<div class="left_column">
			
			<div class="box" id="account_box">
				<h3>Flickr Account</h3>
				<div class="inside">
					
					<p>Looks like you haven't set up your Flickr account yet. Click on the Authenticate button below to setup your Flickr account. When you click Authenticate, you will be redirected to Flickr to authorize access.</p>
					
					<form action="<?=$fp->callback_url?>/auth.php">
						<div class="buttons">
							<input type="submit" class="button" value="Authenticate" />
						</div>
					</form>
					
				</div>
			</div>
			
		</div>
	</div>

<?php }
/*
Otherwise, show all of the configuration options
*/
else { ?>
	
	<?=$fp->print_messages()?>
	
	<div class="boxes clearfix">
		<div class="left_column">
			
			<div class="box" id="account_box">
				<h3>Flickr Account</h3>
				<div class="inside">
					
					<p style="font-size:12px;border:1px solid #e2c822;background-color:#fff9d7;padding:7px;"><strong>Your Facebook account is currently associated with <a href="<?=$fp->flickr->urls_getUserProfile($fp->nsid)?>"><?=$fp->flickr_user['username']?></a> and is authorized with <?=$fp->perms?> permissions.</strong></p>

					<p>Click on the Remove Account button below to remove your association with your Flickr account. Once you remove it, you can either add a different account, or the same one again.</p>

					<fb:dialog id="remove_dialog" cancel_button="1">
						<fb:dialog-title>Remove Flickr Account</fb:dialog-title>
						<fb:dialog-content>
							<h3>Are you sure you want to remove your Flickr account from <fb:application-name linked="false" />?</h3>
							<p>This <strong>will not</strong> remove the application from your Facebook account. You will be given the opportunity to revoke the permissions on Flickr once your account information is removed from <fb:application-name linked="false" />.</p>
						</fb:dialog-content>
						<fb:dialog-button type="button" value="Remove Flickr Account" href="<?=$fp->canvas_url?>/auth.php?remove" />
					</fb:dialog>
					
					<form>
						<div class="buttons">
							<input type="button" class="button" value="Remove Flickr Account" clicktoshowdialog="remove_dialog" />
						</div>
					</form>
					
					<?php
					// Show option to enable write permissions if they only have read
					if ($fp->tagging_beta and $fp->config['flickr_auth'] != 'w'): ?>
						
						<p></p>
						<p>You will need to give write permissions to <fb:application-name linked="false" /> if you want to enable photo tagging.</p>
						
						<form>
							<div class="buttons">
								<input type="button" class="button" value="Give Write Permissions" clicktoshowdialog="write_dialog" />
							</div>
						</form>

						<fb:dialog id="write_dialog" cancel_button=1>
							<fb:dialog-title>Give Write Permissions</fb:dialog-title>
							<fb:dialog-content>
								<h3>Do you want to give write permissions to <fb:application-name linked="false" />?</h3>
								<p><strong>Write permissions</strong> allow <fb:application-name linked="false" /> to access your photos, edit your photo information, and upload photos to your account.</p>
								<p>You will need to give <strong>Write</strong> permission in order to allow photo tagging.</p>
							</fb:dialog-content>
							<fb:dialog-button type="button" value="Give Write Permissions" href="<?=$fp->callback_url?>/auth.php?write" />
						</fb:dialog>

					<?php endif; ?>
					
				</div>
			</div>
			
			<div class="box" id="privacy_box">
				<h3>Privacy</h3>
				<h4>Control what photos are shown and who can see them.</h4>
				<div class="inside">
					<fb:editor action="">

						<fb:editor-custom label="Photo Privacy">
							Show photos marked as 
							<select name="privacy_filter">
								<option value="<?=$fp->privacy_filter['public']?>"<?php if ($fp->config['privacy_filter'] == $fp->privacy_filter['public']) { echo ' selected'; } ?>>Public</option>
								<option value="<?=$fp->privacy_filter['friends']?>"<?php if ($fp->config['privacy_filter'] == $fp->privacy_filter['friends']) { echo ' selected'; } ?>>Friends</option>
								<option value="<?=$fp->privacy_filter['family']?>"<?php if ($fp->config['privacy_filter'] == $fp->privacy_filter['family']) { echo ' selected'; } ?>>Family</option>
								<option value="<?=$fp->privacy_filter['friends_family']?>"<?php if ($fp->config['privacy_filter'] == $fp->privacy_filter['friends_family']) { echo ' selected'; } ?>>Friends &amp; Family</option>
								<option value="<?=$fp->privacy_filter['private']?>"<?php if ($fp->config['privacy_filter'] == $fp->privacy_filter['private']) { echo ' selected'; } ?>>Private</option>
							</select>
							<br/><span class="editor-actions"><small>Public photos will always be shown, in addition to the selected privacy setting.</small></span>
						</fb:editor-custom>

						<fb:editor-custom label="Facebook Visibility">
							Show photos to
							<select name="privacy_visibility">
								<option value="<?=$fp->privacy_visibility['all']?>"<?php if ($fp->config['privacy_visibility'] == $fp->privacy_visibility['all']) { echo ' selected'; } ?>>Everyone</option>
								<option value="<?=$fp->privacy_visibility['friends']?>"<?php if ($fp->config['privacy_visibility'] == $fp->privacy_visibility['friends']) { echo ' selected'; } ?>>My Friends Only</option>
								<option value="<?=$fp->privacy_visibility['non-limited']?>"<?php if ($fp->config['privacy_visibility'] == $fp->privacy_visibility['non-limited']) { echo ' selected'; } ?>>My Friends (non-limited)</option>
							</select>
							<br/><span class="editor-actions"><small>Non-limited excludes anyone on your limited profile list.</small></span>
						</fb:editor-custom>

						<fb:editor-buttonset>
							<fb:editor-button name="fp_privacy" value="Set"/>
							<fb:editor-button name="fp_privacy" value="Reset"/>
							<fb:editor-cancel href="<?=$fp->canvas_url?>/configure.php" />
						</fb:editor-buttonset>

					</fb:editor>
				</div>
			</div>
			
			<div class="box" id="profile_box">
				<h3>Profile Box</h3>
				<h4>Control what your profile box looks like.</h4>
				<div class="inside">
					<fb:if-section-not-added section="profile">
						<p>It looks like you haven't added the profile box yet. Click the button below to add it, then come back here to configure it.</p>
						<fb:add-section-button section="profile" />
						<script type="text/javascript">
						$('profile_box_options').setStyle('display', 'none');
						</script>
					</fb:if-section-not-added>
					<div id="profile_box_options">
						<form action="" method="post">
						<table class="editorkit" border="0" cellspacing="0" style="width:425px"><tr class="width_setter"><th style="width:75px"></th><td></td></tr>

							<tr><th class="detached_label"><label>Display:</label></th><td class="editorkit_row">
								<select name="profile_display" onchange="profilePageOptions(this);" onload="profilePageOptions(this);">
									<option value="<?=$fp->profile_display['last']?>"<?php if ($fp->config['profile_display'] == $fp->profile_display['last']) { echo ' selected'; } ?>>
										Most Recent Photos
									</option>
									<option value="<?=$fp->profile_display['recent']?>"<?php if ($fp->config['profile_display'] == $fp->profile_display['recent']) { echo ' selected'; } ?>>
										Fairly Recent Photos
									</option>
									<option value="<?=$fp->profile_display['random']?>"<?php if ($fp->config['profile_display'] == $fp->profile_display['random']) { echo ' selected'; } ?>>
										Random Photos
									</option>
									<option value="<?=$fp->profile_display['sets']?>"<?php if ($fp->config['profile_display'] == $fp->profile_display['sets']) { echo ' selected'; } ?>>
										Sets
									</option>
									<option value="<?=$fp->profile_display['random_sets']?>"<?php if ($fp->config['profile_display'] == $fp->profile_display['random_sets']) { echo ' selected'; } ?>>
										Random Sets
									</option>
									<option value="<?=$fp->profile_display['overview']?>"<?php if ($fp->config['profile_display'] == $fp->profile_display['overview']) { echo ' selected'; } ?>>
										Overview
									</option>
								</select>
							</td><td class="right_padding"></td></tr>

							<?php $photos_string = ($fp->config['profile_display'] == $fp->profile_display['sets']) ? 'Sets' : 'Photos' ; ?>
							<tr id="num_photos_field"<?=($fp->config['profile_display'] == $fp->profile_display['overview']) ? ' style="display:none;"' : '' ;?>><th class="detached_label"><label id="profile_display_label">Number of <?=$photos_string?>:</label></th><td class="editorkit_row">

								<input type="text" onchange="checkNumPhotos(this);" value="<?=$fp->config['profile_count']?>" name="profile_count" id="profile_count_photos" maxlength="2" class="numphotos" />

								<span class="editor-actions"><small id="profile_display_small">Maximum 30 <?=strtolower($photos_string)?></small></span>
							</td><td class="right_padding"></td></tr>

							<tr id="profile_tags_field"<?=($fp->config['profile_display'] == $fp->profile_display['overview'] or $fp->config['profile_display'] == $fp->profile_display['sets']) ? ' style="display:none;"' : '' ;?>><th class="detached_label"><label>Tags (optional):</label></th><td class="editorkit_row">
								<input type="text" value="<?=$fp->config['profile_tags']?>" name="profile_tags" class="" />
								<span class="editor-actions"><small>Optional comma-separated list of tags</small></span>
							</td><td class="right_padding"></td></tr>

							<tr id="profile_tagmode_field"<?=($fp->config['profile_display'] == $fp->profile_display['overview'] or $fp->config['profile_display'] == $fp->profile_display['sets']) ? ' style="display:none;"' : '' ;?>><th class="detached_label"><label>Tag Mode:</label></th><td class="editorkit_row">
								<select name="profile_tagmode">
									<option value="<?=$fp->profile_tagmode['any']?>"<?php if ($fp->config['profile_tagmode'] == $fp->profile_tagmode['any']) { echo ' selected'; } ?>>
										ANY tag
									</option>
									<option value="<?=$fp->profile_tagmode['all']?>"<?php if ($fp->config['profile_tagmode'] == $fp->profile_tagmode['all']) { echo ' selected'; } ?>>
										ALL tags
									</option>
								</select>
							</td><td class="right_padding"></td></tr>

							<tr id="profile_sortby_field"<?=($fp->config['profile_display'] == $fp->profile_display['overview'] or $fp->config['profile_display'] == $fp->profile_display['sets']) ? ' style="display:none;"' : '' ;?>><th class="detached_label"><label>Sort By:</label></th><td class="editorkit_row">
								<select name="profile_sort" id="profile_sort">
									<option value="<?=$fp->profile_sort['date_posted_desc']?>"<?php if ($fp->config['profile_sort'] == $fp->profile_sort['date_posted_desc']) { echo ' selected'; } ?>>
										Date Posted, Newest to Oldest
									</option>
									<option value="<?=$fp->profile_sort['date_posted_asc']?>"<?php if ($fp->config['profile_sort'] == $fp->profile_sort['date_posted_asc']) { echo ' selected'; } ?>>
										Date Posted, Oldest to Newest
									</option>
									<option value="<?=$fp->profile_sort['date_taken_desc']?>"<?php if ($fp->config['profile_sort'] == $fp->profile_sort['date_taken_desc']) { echo ' selected'; } ?>>
										Date Taken, Newest to Oldest
									</option>
									<option value="<?=$fp->profile_sort['date_taken_asc']?>"<?php if ($fp->config['profile_sort'] == $fp->profile_sort['date_taken_asc']) { echo ' selected'; } ?>>
										Date Taken, Oldest to Newest
									</option>
									<option value="<?=$fp->profile_sort['interesting_desc']?>"<?php if ($fp->config['profile_sort'] == $fp->profile_sort['interesting_desc']) { echo ' selected'; } ?>>
										Interestingness, Most to Least
									</option>
									<option value="<?=$fp->profile_sort['interesting_asc']?>"<?php if ($fp->config['profile_sort'] == $fp->profile_sort['interesting_asc']) { echo ' selected'; } ?>>
										Interestingness, Least to Most
									</option>
								</select>
							</td><td class="right_padding"></td></tr>

							<tr><th></th><td class="editorkit_buttonset">
								<input type="submit" class="editorkit_button action" value="Set" name="fp_profile" />
								<input type="submit" class="editorkit_button action" value="Reset" name="fp_profile" />
								<input type="submit" class="editorkit_button action" name="fp_profile" value="Preview" clickrewriteurl="<?=$fp->callback_url?>/profile.php?handle=<?=$fp->uid?>&amp;preview" clickrewriteid="profilepreview" clicktoshow="profilepreview"/>
								<span class="cancel_link"><span>or</span><a href="<?=$fp->canvas_url?>/configure.php">Cancel</a></span>
							</td><td class="right_padding"></td></tr>

						</table></form>
						<div id="profilepreview" style="display:none;width:420px;margin:auto;"></div>
					</div>
				</div>
			</div>
			
		</div>
		<div class="right_column">
			
			<div class="box" id="features_box">
				<h3>Features</h3>
				<h4>Enable and disable application features.</h4>
				<div class="inside">
					<form action="" method="post">
						<? /* <label for="enable_newsfeed">
							<input type="checkbox" id="enable_newsfeed" name="enable_newsfeed" value="1" <?=($fp->config['enable_newsfeed']) ? 'checked ' : '' ?> /> News Feed Notifications
						</label> */ ?>
						
						<?php if ($fp->tagging_beta): ?>
						<label for="enable_tagging">
							<input type="checkbox" id="enable_tagging" name="enable_tagging" value="1" <?=($fp->config['enable_tagging']) ? 'checked ' : '' ?> <?=($fp->config['flickr_auth'] == 'r') ? 'disabled' : '' ?> /> Photo Tagging
						</label>
						<?php endif; ?>
						
						<label for="enable_comments">
							<input type="checkbox" id="enable_comments" name="enable_comments" value="1" <?=($fp->config['enable_comments']) ? 'checked="checked" ' : ' ' ?> /> Photo and Photoset Comments
						</label>
						<label for="enable_gallery_photostream">
							<input type="checkbox" id="enable_gallery_photostream" name="enable_gallery_photostream" value="1" <?=($fp->config['enable_gallery_photostream']) ? 'checked="checked" ' : ' '?>/> Photostream Page
						</label>
						<label for="enable_gallery_photosets">
							<input type="checkbox" id="enable_gallery_photosets" name="enable_gallery_photosets" value="1" <?=($fp->config['enable_gallery_photosets']) ? 'checked="checked" ' : ' '?>/> Photosets Page
						</label>
						<label for="enable_gallery_collections">
							<input type="checkbox" id="enable_gallery_collections" name="enable_gallery_collections" value="1" <?=($fp->config['enable_gallery_collections']) ? 'checked="checked" ' : ' '?>/> Collections Page
						</label>
						<label for="enable_gallery_geotagged">
							<input type="checkbox" id="enable_gallery_geotagged" name="enable_gallery_geotagged" value="1" <?=($fp->config['enable_gallery_geotagged']) ? 'checked="checked" ' : ' '?>/> Geotagged Photos Page
						</label>
						
						<div class="buttons">
							<input type="submit" class="button" value="Set" name="fp_features" />
							<input type="submit" class="button" value="Reset" name="fp_features" />
							<span class="cancel_link">or<a href="<?=$fp->canvas_url?>/configure.php">Cancel</a></span>
						</div>
						
					</form>
				</div>
			</div>
			
			<div style="margin-bottom: 20px;">
				<div class="box" id="add_info_box">
					<h3>Info Box</h3>
					<div class="inside">
						<fb:if-section-not-added section="info">
							<fb:add-section-button section="info" />
						<fb:else>
							<p>The info box has been added to your profile.</p>
						</fb:else></fb:if-section-not-added>
					</div>
				</div>
			</div>
			
			<div class="box" id="troubleshooting_box">
				<h3>Problems</h3>
				<h4>Try these if you're having problems.</h4>
				<div class="inside">
					<p>If you're having problems, please <a href="http://www.facebook.com/board.php?uid=<?=$fp->app_properties['app_id']?>"><fb:intl desc="check the discussion board">check the discussion board</fb:intl></a>.</p>
				</div>
			</div>
			
			<div class="box" id="donate_box">
				<h3>Donate</h3>
				<div class="inside">
					<p>If you find this application really useful, please consider donating.</p>
					<form action="https://www.paypal.com/cgi-bin/webscr" method="post">
					<input type="hidden" name="cmd" value="_s-xclick">
					<input type="hidden" name="encrypted" value="-----BEGIN PKCS7-----MIIHLwYJKoZIhvcNAQcEoIIHIDCCBxwCAQExggEwMIIBLAIBADCBlDCBjjELMAkGA1UEBhMCVVMxCzAJBgNVBAgTAkNBMRYwFAYDVQQHEw1Nb3VudGFpbiBWaWV3MRQwEgYDVQQKEwtQYXlQYWwgSW5jLjETMBEGA1UECxQKbGl2ZV9jZXJ0czERMA8GA1UEAxQIbGl2ZV9hcGkxHDAaBgkqhkiG9w0BCQEWDXJlQHBheXBhbC5jb20CAQAwDQYJKoZIhvcNAQEBBQAEgYANUWHF10MH1pPUjg72P9+fbQskIdy649/p7GT9at2kqhrbHkbp6HY5k6WraxvnuBXkKmOSPzllY8mhjgThBvsVwwL+mwbYsdBWgA7GkAr61yM+srtwjHpbvbHVq2fKGcBIxDrxeAzWi2szvuBdDfZ6F7tT10tdlNczTyHZ9WUOszELMAkGBSsOAwIaBQAwgawGCSqGSIb3DQEHATAUBggqhkiG9w0DBwQI0hppqOVuzLWAgYg1LZ/nn802Y0OJF+7iuMt+q/4nfVWMkOkU5RJPOiZbwnOsGADihsi5zyc+EmTD9eD0u/gjLan0cg+WRSj2Vuj0fEcMJvfYmVIlJ8dDOtS1fCeatWwsp9yckHkFPuKpNC9TRXVGt08Ikge1C9mEv397QF+cYyUwuZ+GWDEN+L0Tph0VstNDWhptoIIDhzCCA4MwggLsoAMCAQICAQAwDQYJKoZIhvcNAQEFBQAwgY4xCzAJBgNVBAYTAlVTMQswCQYDVQQIEwJDQTEWMBQGA1UEBxMNTW91bnRhaW4gVmlldzEUMBIGA1UEChMLUGF5UGFsIEluYy4xEzARBgNVBAsUCmxpdmVfY2VydHMxETAPBgNVBAMUCGxpdmVfYXBpMRwwGgYJKoZIhvcNAQkBFg1yZUBwYXlwYWwuY29tMB4XDTA0MDIxMzEwMTMxNVoXDTM1MDIxMzEwMTMxNVowgY4xCzAJBgNVBAYTAlVTMQswCQYDV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waTEcMBoGCSqGSIb3DQEJARYNcmVAcGF5cGFsLmNvbQIBADAJBgUrDgMCGgUAoF0wGAYJKoZIhvcNAQkDMQsGCSqGSIb3DQEHATAcBgkqhkiG9w0BCQUxDxcNMDkwMjE2MDE0MzI0WjAjBgkqhkiG9w0BCQQxFgQUFMrIDjD+REeEA0wNL5m3i34L9NIwDQYJKoZIhvcNAQEBBQAEgYBp+k5Hwn+hB+kJ9w+a46FqF/gOw9F21YHVoMrqVTYXSKU7ZvvO+70W0hMA5++Bn+7DtohuKL+jZbwm4Arp34hK9M6zrvdm/DxLJLFOAx7kbH8bx0ZeIbWz7N/2NlKDpIxSDUmCTWAnsD+lvPWAxwjRhZ8KWL2TUM+BgDRFiplUXw==-----END PKCS7-----
					">
					<input type="image" src="https://www.paypal.com/en_US/i/btn/btn_donate_SM.gif" border="0" name="submit" alt="">
					<img alt="" border="0" src="https://www.paypal.com/en_US/i/scr/pixel.gif" width="1" height="1">
					</form>
				</div>
			</div>
			
		</div>
	</div>

<?php } ?>

<?=$fp->get_disclaimer(true)?>
<?=$fp->get_analytics()?>